﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Security.Permissions;

namespace TfsCommitMonitor
{
	internal class TfsListView : ListView
	{
		internal TfsListView()
		{
			FullRowSelect = true;
			View = View.Details;
		}

        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
		protected override void WndProc(ref Message message)
		{
			const int WM_PAINT = 0xf;

			// if the control is in details view mode and columns
			// have been added, then intercept the WM_PAINT message
			// and reset the last column width to fill the list view
			switch (message.Msg)
			{
				case WM_PAINT:
					if (View == View.Details && Columns.Count > 0)
						Columns[Columns.Count - 1].Width = -2;
					break;
			}

			// pass messages on to the base control for processing
			base.WndProc(ref message);
		}
	}
}
